using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using System.Linq;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;

namespace ICP_MS;

public class ExperimentDB
{
	private ISessionFactory _sessionFactory = null;

	private SQLiteConnection dest = null;

	private string localDb = "";

	public Exception LastException { get; set; }

	public bool Init(string dbPath)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Expected O, but got Unknown
		try
		{
			localDb = dbPath;
			Configuration cfg = new Configuration();
			string connectString = "Data Source=" + dbPath + ";Version=3";
			ConfigurationExtensions.SessionFactoryName(cfg, "DynamicCfg");
			cfg.SetProperty("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
			cfg.SetProperty("dialect", "NHibernate.Dialect.SQLiteDialect");
			cfg.SetProperty("query.substitutions", "true=1;false=0");
			cfg.SetProperty("show_sql", "false");
			cfg.SetProperty("connection.connection_string", connectString);
			cfg.SetProperty("hbm2ddl.auto", "update");
			cfg.AddAssembly(typeof(AnalyteIsotope).Assembly);
			_sessionFactory = cfg.BuildSessionFactory();
			SQLiteConnection source = new SQLiteConnection("Data Source=" + dbPath + ";Version=3");
			try
			{
				((DbConnection)(object)source).Open();
				dest = new SQLiteConnection("Data Source=:memory:;Version=3");
				((DbConnection)(object)dest).Open();
				source.BackupDatabase(dest, "main", "main", -1, (SQLiteBackupCallback)null, 100);
				((DbConnection)(object)source).Close();
			}
			finally
			{
				((IDisposable)source)?.Dispose();
			}
			return true;
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			InserLog("Database", "Init experiment database error.", ex.Message, "Error");
		}
		return false;
	}

	public bool CheckDataBase()
	{
		return true;
	}

	public bool Close()
	{
		_sessionFactory.Close();
		((IDisposable)_sessionFactory).Dispose();
		((DbConnection)(object)dest).Close();
		((Component)(object)dest).Dispose();
		return true;
	}

	public ISession GetSession()
	{
		return _sessionFactory.OpenSession((IDbConnection)dest);
	}

	public Platform GetPlatform(string name = "last")
	{
		Platform plat = null;
		ISession session = GetSession();
		try
		{
			IList<Platform> plats = session.CreateQuery("from Platform plat where plat.name=:name").SetString("name", name).List<Platform>();
			if (plats != null && plats.Count > 0)
			{
				plat = plats[plats.Count - 1];
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return plat;
	}

	public bool SavePlatform(Platform plat)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)plat);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public PlasmaPara GetPlasma(string name = "last")
	{
		PlasmaPara plasma = null;
		ISession session = GetSession();
		try
		{
			IList<PlasmaPara> plasmas = session.CreateQuery("from PlasmaPara plasma where plasma.Name=:name").SetString("name", name).List<PlasmaPara>();
			if (plasmas != null && plasmas.Count > 0)
			{
				plasma = plasmas.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return plasma;
	}

	public bool SavePlasma(PlasmaPara plasma)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)plasma);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public RFS GetRFS(string name = "last")
	{
		RFS rfs = null;
		ISession session = GetSession();
		try
		{
			IList<RFS> rfss = session.CreateQuery("from RFS rfs where rfs.name=:name").SetString("name", name).List<RFS>();
			if (rfss != null && rfss.Count > 0)
			{
				rfs = rfss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return rfs;
	}

	public bool SaveRFS(RFS rfs)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)rfs);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public Injector GetInjector(string name = "last")
	{
		Injector inj = null;
		ISession session = GetSession();
		try
		{
			IList<Injector> injs = session.CreateQuery("from Injector inj where inj.Name=:name").SetString("name", name).List<Injector>();
			if (injs != null && injs.Count > 0)
			{
				inj = injs.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return inj;
	}

	public bool SaveInjector(Injector inj)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)inj);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveStableConfig(StableConfig stableconfig)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)stableconfig);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveAutoSampleTable(AutoSampleTable autoSampleTable)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)autoSampleTable);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public AutoSampleTable GetAutoSampleTable()
	{
		AutoSampleTable rfs = null;
		ISession session = GetSession();
		try
		{
			IList<AutoSampleTable> rfss = session.CreateCriteria(typeof(AutoSampleTable)).List<AutoSampleTable>();
			if (rfss != null && rfss.Count > 0)
			{
				rfs = rfss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return rfs;
	}

	public StableConfig GetStableConfig()
	{
		StableConfig rfs = null;
		ISession session = GetSession();
		try
		{
			IList<StableConfig> rfss = session.CreateCriteria(typeof(StableConfig)).List<StableConfig>();
			if (rfss != null && rfss.Count > 0)
			{
				rfs = rfss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return rfs;
	}

	public X2Lens GetX2Lens(string name = "last")
	{
		X2Lens lens = null;
		ISession session = GetSession();
		try
		{
			IList<X2Lens> lenss = session.CreateQuery("from X2Lens lens where lens.name=:name").SetString("name", name).List<X2Lens>();
			if (lenss != null && lenss.Count > 0)
			{
				lens = lenss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return lens;
	}

	public bool SaveX2Lens(X2Lens lens)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)lens);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public AnalyteIsotope GetAnalyteIsotopeById(int id)
	{
		AnalyteIsotope isotope = null;
		ISession session = GetSession();
		try
		{
			isotope = session.Get<AnalyteIsotope>((object)id);
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotope = null;
			InserLog("Database", "Get isotope by id error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotope;
	}

	public AnalyteIsotope GetAnalyteIsotopeByIntMass(int IntMass)
	{
		AnalyteIsotope isotope = null;
		ISession session = GetSession();
		try
		{
			isotope = session.Get<AnalyteIsotope>((object)IntMass);
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotope = null;
			InserLog("Database", "Get isotope by id error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotope;
	}

	public AnalyteIsotope GetAnalyteIsotopeBySymbol(string symbol)
	{
		AnalyteIsotope isotope = null;
		ISession session = GetSession();
		try
		{
			IList<AnalyteIsotope> isotopes = null;
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.symbol=:symbol").SetString("symbol", symbol).List<AnalyteIsotope>();
			if (isotopes != null && isotopes.Count > 0)
			{
				isotope = isotopes[0];
			}
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotope = null;
			InserLog("Database", "Get isotope by symbol error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotope;
	}

	public bool SaveIsotope(IList<AnalyteIsotope> isotopes)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (AnalyteIsotope std in isotopes)
				{
					session.SaveOrUpdate((object)std);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save tempIsotopes error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public AnalyteIsotope GetAnalyteIsotopeIDBySymbol(string symbol)
	{
		AnalyteIsotope isotope = null;
		ISession session = GetSession();
		try
		{
			IList<AnalyteIsotope> isotopes = null;
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.symbol=:symbol").SetString("symbol", symbol).List<AnalyteIsotope>();
			if (isotopes != null && isotopes.Count > 0)
			{
				isotope = isotopes[0];
			}
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotope = null;
			InserLog("Database", "Get isotope by symbol error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotope;
	}

	public bool DeleteSelectedIsotopeAll()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from SelectedAnlytes");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete peak regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<AnalyteIsotope> GetAnalyteIsotopesBySymbol(string symbol)
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.symbol=:symbol").SetString("symbol", symbol).List<AnalyteIsotope>();
		}
		catch
		{
			isotopes = null;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public IList<AnalyteIsotope> GetAnalyteIsotopes()
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateCriteria(typeof(AnalyteIsotope)).List<AnalyteIsotope>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotopes = null;
			InserLog("Database", "Get isotopes error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public bool SaveAnalyteIsotope(AnalyteIsotope isotope)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tx = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)isotope);
				session.Flush();
				tx.Commit();
				return true;
			}
			catch (Exception ex)
			{
				LastException = ex;
				tx.Rollback();
			}
			finally
			{
				((IDisposable)tx)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<AnalyteIsotope> GetAnalyteIsotopesMax()
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.defaultSelection = 1").List<AnalyteIsotope>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotopes = null;
			InserLog("Database", "Get isotopes error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public IList<AnalyteIsotope> GetAnalyteIsotopesByAtomic(string atomic)
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.atomicSymbol=:atomic").SetString("atomic", atomic).List<AnalyteIsotope>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotopes = null;
			InserLog("Database", "Get isotope by atomic error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public IList<InterferenceEquation> GetInterferenceEquation(int peakId)
	{
		IList<InterferenceEquation> equations = null;
		try
		{
			ISession session = GetSession();
			try
			{
				equations = session.CreateQuery("from InterferenceEquation equation where equation.peakId=:peakId").SetInt32("peakId", peakId).List<InterferenceEquation>();
			}
			finally
			{
				((IDisposable)session)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			equations = null;
			LastException = ex;
			InserLog("Database", "Get interference equaticon error.", ex.Message, "Error");
		}
		return equations;
	}

	public bool SaveInterferenceEquation(InterferenceEquation equation)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tx = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)equation);
				session.Flush();
				tx.Commit();
				return true;
			}
			catch (Exception ex)
			{
				LastException = ex;
				tx.Rollback();
			}
			finally
			{
				((IDisposable)tx)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteInterferenceEuations(int peakId)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from InterferenceEquation equation where equation.peakId = '" + peakId + "'");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				InserLog("Database", "DeleteInterferenceEuations", ex.Message, "Error");
				tran.Rollback();
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public string GetSymbolById(int peakID)
	{
		string symbol = null;
		ISession session = GetSession();
		try
		{
			AnalyteIsotope isotope = session.Get<AnalyteIsotope>((object)peakID);
			symbol = isotope.symbol;
		}
		catch (Exception ex)
		{
			symbol = null;
			LastException = ex;
			InserLog("Database", "Get symbol by id error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return symbol;
	}

	public IList<ExclusionRegion> GetExclusionRegions()
	{
		IList<ExclusionRegion> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(ExclusionRegion)).AddOrder(Order.Asc("id")).List<ExclusionRegion>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			regions = null;
			InserLog("Database", "Get exclusion regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public IList<AnalyteIsotope> GetPolyIonsIn()
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.analyteType = 2 or isotope.analyteType = 3").List<AnalyteIsotope>().Distinct()
				.ToList();
		}
		catch
		{
			isotopes = null;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public IList<PolyIons> GetPolyIons()
	{
		IList<PolyIons> poly = null;
		ISession session = GetSession();
		try
		{
			return session.CreateCriteria(typeof(PolyIons)).List<PolyIons>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			poly = null;
			InserLog("Database", "Get poly ions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public IList<AnalyteIsotope> GetSelectAnlyteIsotopes()
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			IList<SelectedAnlytes> selects = session.CreateCriteria(typeof(SelectedAnlytes)).List<SelectedAnlytes>();
			if (selects != null)
			{
				isotopes = new List<AnalyteIsotope>();
				foreach (SelectedAnlytes s in selects)
				{
					isotopes.Add(session.Get<AnalyteIsotope>((object)s.isotopeId));
				}
			}
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotopes = null;
			InserLog("Database", "Get selected isotopes error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public bool AddSelectedIsotope(AnalyteIsotope isotope)
	{
		ISession session = GetSession();
		try
		{
			ITransaction transaction = session.BeginTransaction();
			try
			{
				SelectedAnlytes selected = new SelectedAnlytes
				{
					isotopeId = isotope.id
				};
				try
				{
					session.Save((object)selected);
					transaction.Commit();
					return true;
				}
				catch (Exception ex2)
				{
					Exception ex = (LastException = ex2);
					transaction.Rollback();
					InserLog("Database", "Save seleted isotope error.", ex.Message, "Error");
				}
			}
			finally
			{
				((IDisposable)transaction)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteSelectedIsotope(AnalyteIsotope isotope)
	{
		ISession session = GetSession();
		try
		{
			ITransaction transaction = session.BeginTransaction();
			try
			{
				session.Delete("from SelectedAnlytes where isotopeId = '" + isotope.id + "'");
				transaction.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				transaction.Rollback();
				InserLog("Database", "Delete selected isotope error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)transaction)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<ScanRegions> GetExpSurveyRegions()
	{
		IList<ScanRegions> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(ScanRegions)).Add((ICriterion)(object)Restrictions.Eq("name", (object)"Survey")).List<ScanRegions>();
		}
		catch (Exception ex)
		{
			Log.InsertLog("方法数据库", "获取全扫描区域", ex.Message, (Severity)3);
			LastException = ex;
			regions = null;
			InserLog("Database", "Get scan regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public bool DeleteExpSurveyRegions()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from ScanRegions where name = 'Survey'");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Get survey regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<BlankCalibration> GetExpBlankCalibration()
	{
		IList<BlankCalibration> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(BlankCalibration)).List<BlankCalibration>();
		}
		catch (Exception ex)
		{
			Log.InsertLog("方法数据库", "获取空白校正数据", ex.Message, (Severity)3);
			LastException = ex;
			regions = null;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public bool DeleteExpBlankCalibration()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from BlankCalibration");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete Blank Calibration data  error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpBlankCalibration(IList<BlankCalibration> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (BlankCalibration region in regions)
				{
					region.id = 0;
					session.Save((object)region);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save BlankCalibration error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpSurveyRegions(IList<ScanRegions> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (ScanRegions region in regions)
				{
					region.id = 0;
					session.Save((object)region);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save survey regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<ScanRegions> GetExpScanRegions()
	{
		IList<ScanRegions> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(ScanRegions)).Add((ICriterion)(object)Restrictions.Eq("name", (object)"Scan")).List<ScanRegions>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			regions = null;
			InserLog("Database", "Get scan regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public bool DeleteExpScanRegions()
	{
		ISession session = GetSession();
		try
		{
			ITransaction transaction = session.BeginTransaction();
			try
			{
				session.CreateQuery("delete from ScanRegions where name = 'Scan'").ExecuteUpdate();
				transaction.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				transaction.Rollback();
				InserLog("Database", "Delete scan regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)transaction)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpScanRegions(IList<ScanRegions> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (ScanRegions region in regions)
				{
					region.id = 0;
					session.Save((object)region);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save scan regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<PeakRegions> GetExpPeakRegions()
	{
		IList<PeakRegions> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(PeakRegions)).List<PeakRegions>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			regions = null;
			InserLog("Database", "Get peak regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public bool DeleteExpPeakRegions()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from PeakRegions");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete peak regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpPeakRegions(IList<PeakRegions> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (PeakRegions region in regions)
				{
					region.id = 0;
					session.Save((object)region);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save peak regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<IsotopeInfos> GetExpIsotopes()
	{
		IList<IsotopeInfos> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateCriteria(typeof(IsotopeInfos)).List<IsotopeInfos>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotopes = null;
			InserLog("Database", "Get analyse isotopes error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public bool DeleteExpIsotopes()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IsotopeInfos");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete analyse isotopes error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpIsotopes(IList<IsotopeInfos> isotopes)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpIsotopeInfos (id, name, symbol, mass, inter, technique,\r\n                               ion,concentration,profile,method,force,semiquant,visible,units,\r\n                             withInterference,isInterference,PASlope,PAIntercept)\r\n                                         VALUES  (@id, @name, @symbol, @mass, @inter, @technique,\r\n                               @ion,@concentration,@profile,@method,@force,@semiquant,@visible,@units,\r\n                             @withInterference,@isInterference,@PASlope,@PAIntercept)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (IsotopeInfos result in isotopes)
				{
					count = (result.id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@id", (object)result.id);
					insertRngCmd.Parameters.AddWithValue("@name", (object)result.name);
					insertRngCmd.Parameters.AddWithValue("@symbol", (object)result.symbol);
					insertRngCmd.Parameters.AddWithValue("@mass", (object)result.mass);
					insertRngCmd.Parameters.AddWithValue("@inter", (object)result.inter);
					insertRngCmd.Parameters.AddWithValue("@technique", (object)result.technique);
					insertRngCmd.Parameters.AddWithValue("@ion", (object)result.ion);
					insertRngCmd.Parameters.AddWithValue("@concentration", (object)result.concentration);
					insertRngCmd.Parameters.AddWithValue("@profile", (object)result.profile);
					insertRngCmd.Parameters.AddWithValue("@method", (object)result.method);
					insertRngCmd.Parameters.AddWithValue("@force", (object)result.force);
					insertRngCmd.Parameters.AddWithValue("@semiquant", (object)result.semiquant);
					insertRngCmd.Parameters.AddWithValue("@visible", (object)result.visible);
					insertRngCmd.Parameters.AddWithValue("@withInterference", (object)result.withInterference);
					insertRngCmd.Parameters.AddWithValue("@isInterference", (object)result.isInterference);
					insertRngCmd.Parameters.AddWithValue("@PASlope", (object)result.PASlope);
					insertRngCmd.Parameters.AddWithValue("@PAIntercept", (object)result.PAIntercept);
					insertRngCmd.Parameters.AddWithValue("@units", (object)result.units);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpResults Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public IList<SamplesInfos> GetExpSamples()
	{
		IList<SamplesInfos> samples = null;
		ISession session = GetSession();
		try
		{
			samples = session.CreateCriteria(typeof(SamplesInfos)).List<SamplesInfos>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			samples = null;
			InserLog("Database", "Get samples error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return samples;
	}

	public bool DeleteExpSamples()
	{
		DateTime time1 = DateTime.Now;
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "delete from ExpSamplesInfos";
				SQLiteTransaction transaction = dest.BeginTransaction();
				((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				((DbTransaction)(object)transaction).Commit();
				TimeSpan timeSpan = DateTime.Now - time1;
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "DeleteExpSamples Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public bool DeleteExpSamples(SamplesInfos sample)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete((object)sample);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete samples error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpSamples(IList<SamplesInfos> samples)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpSamplesInfos (id, guid, number, report, label, type,\r\n                               surveys,mains,predilution,inter,blank,time,status,refer,curveId,rackNumber,vialNumber,ZDepth,mass,volume)\r\n                                         VALUES  (@id, @guid, @number, @report, @label, @type,@surveys,@mains,@predilution,\r\n                               @inter,@blank,@time,@status,@refer,@curveId,@rackNumber,@vialNumber,@ZDepth,@mass,@volume)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (SamplesInfos result in samples)
				{
					count = (result.id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@id", (object)result.id);
					insertRngCmd.Parameters.AddWithValue("@guid", (object)result.guid);
					insertRngCmd.Parameters.AddWithValue("@number", (object)result.number);
					insertRngCmd.Parameters.AddWithValue("@report", (object)result.report);
					insertRngCmd.Parameters.AddWithValue("@label", (object)result.label);
					insertRngCmd.Parameters.AddWithValue("@type", (object)result.type);
					insertRngCmd.Parameters.AddWithValue("@surveys", (object)result.surveys);
					insertRngCmd.Parameters.AddWithValue("@mains", (object)result.mains);
					insertRngCmd.Parameters.AddWithValue("@predilution", (object)result.predilution);
					insertRngCmd.Parameters.AddWithValue("@inter", (object)result.inter);
					insertRngCmd.Parameters.AddWithValue("@blank", (object)result.blank);
					insertRngCmd.Parameters.AddWithValue("@time", (object)result.time);
					insertRngCmd.Parameters.AddWithValue("@status", (object)result.status);
					insertRngCmd.Parameters.AddWithValue("@refer", (object)result.refer);
					insertRngCmd.Parameters.AddWithValue("@curveId", (object)result.curveId);
					insertRngCmd.Parameters.AddWithValue("@rackNumber", (object)result.rackNumber);
					insertRngCmd.Parameters.AddWithValue("@vialNumber", (object)result.vialNumber);
					insertRngCmd.Parameters.AddWithValue("@ZDepth", (object)result.ZDepth);
					insertRngCmd.Parameters.AddWithValue("@mass", (object)result.mass);
					insertRngCmd.Parameters.AddWithValue("@volume", (object)result.volume);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpResults Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public bool SaveExpSamples(SamplesInfos sample)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				sample.id = 0;
				session.Save((object)sample);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save samples error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<StandardConcentration> GetExpStdConcs()
	{
		IList<StandardConcentration> stdCons = null;
		ISession session = GetSession();
		try
		{
			stdCons = session.CreateCriteria(typeof(StandardConcentration)).List<StandardConcentration>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			stdCons = null;
			InserLog("Database", "Get standard concentrations error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return stdCons;
	}

	public bool DeleteExpStdConcs()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from StandardConcentration");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete standard concentrations error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpStdConcs(IList<StandardConcentration> stdConcs)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (StandardConcentration std in stdConcs)
				{
					std.id = 0;
					session.Save((object)std);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save std concentrations error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<QCSConcentration> GetQCSConcs()
	{
		IList<QCSConcentration> stdCons = null;
		ISession session = GetSession();
		try
		{
			stdCons = session.CreateCriteria(typeof(QCSConcentration)).List<QCSConcentration>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			stdCons = null;
			InserLog("Database", "Get qcs concentrations error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return stdCons;
	}

	public bool DeleteQCSConcs()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from QCSConcentration");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete qcs concentrations error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveQCSConcs(IList<QCSConcentration> stdConcs)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (QCSConcentration std in stdConcs)
				{
					std.id = 0;
					session.Save((object)std);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save qcs concentrations error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<AnalyseInfos> GetExpResults()
	{
		IList<AnalyseInfos> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(AnalyseInfos)).List<AnalyseInfos>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			results = null;
			InserLog("Database", "Get results error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpResults()
	{
		DateTime time1 = DateTime.Now;
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "delete from ExpAnalyseInfos";
				SQLiteTransaction transaction = dest.BeginTransaction();
				((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				((DbTransaction)(object)transaction).Commit();
				TimeSpan timeSpan = DateTime.Now - time1;
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpResults Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public bool DeleteExpResults(int sampleid)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from AnalyseInfos where sampleId ='" + sampleid + "'");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpResults(IList<AnalyseInfos> results)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpAnalyseInfos (id, sampleId, label, isotopeId, symbol, number,\r\n                               intensity,IntensityPC,IntensityANA,icps,concentration,test,exclude)\r\n                                         VALUES  (@id,@sampleId,@label,@istpId,@symbol,@number,\r\n                               @int,@IntPC,@IntANA,@icps,@conc,@test,@exc)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (AnalyseInfos result in results)
				{
					count = (result.id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@id", (object)result.id);
					insertRngCmd.Parameters.AddWithValue("@sampleId", (object)result.sampleId);
					insertRngCmd.Parameters.AddWithValue("@label", (object)result.label);
					insertRngCmd.Parameters.AddWithValue("@istpId", (object)result.isotopeId);
					insertRngCmd.Parameters.AddWithValue("@symbol", (object)result.symbol);
					insertRngCmd.Parameters.AddWithValue("@number", (object)result.number);
					insertRngCmd.Parameters.AddWithValue("@int", (object)result.intensity);
					insertRngCmd.Parameters.AddWithValue("@IntPC", (object)result.IntensityPC);
					insertRngCmd.Parameters.AddWithValue("@IntANA", (object)result.IntensityANA);
					insertRngCmd.Parameters.AddWithValue("@icps", (object)result.icps);
					insertRngCmd.Parameters.AddWithValue("@conc", (object)result.concentration);
					insertRngCmd.Parameters.AddWithValue("@test", (object)result.test);
					insertRngCmd.Parameters.AddWithValue("@exc", (object)result.exclude);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpResults Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public IList<StatisticResults> GetExpStatistics()
	{
		IList<StatisticResults> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(StatisticResults)).List<StatisticResults>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			results = null;
			InserLog("Database", "Get statistics results error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpStatistics()
	{
		DateTime time1 = DateTime.Now;
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "delete from ExpStatisticResults";
				SQLiteTransaction transaction = dest.BeginTransaction();
				((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				((DbTransaction)(object)transaction).Commit();
				TimeSpan timeSpan = DateTime.Now - time1;
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "DeleteExpStatistics Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public bool DeleteExpStatistics(int sampleid)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from StatisticResults where sampleId ='" + sampleid + "'");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete statstics results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpStatistics(IList<StatisticResults> results)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpStatisticResults (id, sampleId, label, isotopeId, symbol, avgCon,\r\n                               sdCon,rsdCon,avgUICPS,avgUICPSPC,avgUICPSANA,sdUICPS,rsdUICPS,avgCPS,sdCPS,rsdCPS,stdCon,include)\r\n                                         VALUES  (@id,@sampleId,@label,@isotopeId,@symbol,@avgCon,\r\n                               @sdCon,@rsdCon,@avgUICPS,@avgUICPSPC,@avgUICPSANA,@sdUICPS,@rsdUICPS,@avgCPS,@sdCPS,@rsdCPS,@stdCon,@include)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (StatisticResults result in results)
				{
					count = (result.id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@id", (object)result.id);
					insertRngCmd.Parameters.AddWithValue("@sampleId", (object)result.sampleId);
					insertRngCmd.Parameters.AddWithValue("@label", (object)result.label);
					insertRngCmd.Parameters.AddWithValue("@isotopeId", (object)result.isotopeId);
					insertRngCmd.Parameters.AddWithValue("@symbol", (object)result.symbol);
					insertRngCmd.Parameters.AddWithValue("@avgCon", (object)result.avgCon);
					insertRngCmd.Parameters.AddWithValue("@sdCon", (object)result.sdCon);
					insertRngCmd.Parameters.AddWithValue("@rsdCon", (object)result.rsdCon);
					insertRngCmd.Parameters.AddWithValue("@avgUICPS", (object)result.avgUICPS);
					insertRngCmd.Parameters.AddWithValue("@avgUICPSPC", (object)result.avgUICPSPC);
					insertRngCmd.Parameters.AddWithValue("@avgUICPSANA", (object)result.avgUICPSANA);
					insertRngCmd.Parameters.AddWithValue("@sdUICPS", (object)result.sdUICPS);
					insertRngCmd.Parameters.AddWithValue("@rsdUICPS", (object)result.rsdUICPS);
					insertRngCmd.Parameters.AddWithValue("@avgCPS", (object)result.avgCPS);
					insertRngCmd.Parameters.AddWithValue("@sdCPS", (object)result.sdCPS);
					insertRngCmd.Parameters.AddWithValue("@rsdCPS", (object)result.rsdCPS);
					insertRngCmd.Parameters.AddWithValue("@stdCon", (object)result.stdCon);
					insertRngCmd.Parameters.AddWithValue("@include", (object)result.include);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpStatistics Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public IList<IsotopeRatio> GetExpIsotopeRatios()
	{
		IList<IsotopeRatio> ratios = null;
		ISession session = GetSession();
		try
		{
			ratios = session.CreateCriteria(typeof(IsotopeRatio)).List<IsotopeRatio>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			ratios = null;
			InserLog("Database", "Get isotopes ratios error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return ratios;
	}

	public bool DeleteExpIsotopeRatio(IsotopeRatio ratio)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete((object)ratio);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope reatio error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteExpIsotopeRatio()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IsotopeRatio");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope reatio error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteExpIsotopeRatios()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IsotopeRatio");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratios error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpIsotopeRatio(IsotopeRatio ratio)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Save((object)ratio);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save isotope ratio error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpIsotopeRatios(IList<IsotopeRatio> ratios)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpIsotopeRatio (Id, Name, NumeratorId, NumeratorSym, NumeratorMass, DenominatorId,\r\n                               DenominatorSym,DenominatorMass,Method,STDCon,Inter,Technique)\r\n                                         VALUES  (@Id, @Name, @NumeratorId, @NumeratorSym, @NumeratorMass, @DenominatorId,\r\n                               @DenominatorSym,@DenominatorMass,@Method,@STDCon,@Inter,@Technique)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (IsotopeRatio result in ratios)
				{
					count = (result.Id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@Id", (object)result.Id);
					insertRngCmd.Parameters.AddWithValue("@Name", (object)result.Name);
					insertRngCmd.Parameters.AddWithValue("@NumeratorId", (object)result.NumeratorId);
					insertRngCmd.Parameters.AddWithValue("@NumeratorSym", (object)result.NumeratorSym);
					insertRngCmd.Parameters.AddWithValue("@NumeratorMass", (object)result.NumeratorMass);
					insertRngCmd.Parameters.AddWithValue("@DenominatorId", (object)result.DenominatorId);
					insertRngCmd.Parameters.AddWithValue("@DenominatorSym", (object)result.DenominatorSym);
					insertRngCmd.Parameters.AddWithValue("@DenominatorMass", (object)result.DenominatorMass);
					insertRngCmd.Parameters.AddWithValue("@Method", (object)result.Method);
					insertRngCmd.Parameters.AddWithValue("@STDCon", (object)result.STDCon);
					insertRngCmd.Parameters.AddWithValue("@Inter", (object)result.Inter);
					insertRngCmd.Parameters.AddWithValue("@Technique", (object)result.Technique);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpIsotopeRatios Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public IList<RatioResults> GetExpRatioResults()
	{
		IList<RatioResults> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(RatioResults)).List<RatioResults>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			results = null;
			InserLog("Database", "Get isotope ratio results error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpRatioResults()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from RatioResults");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratio results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteExpRatioResults(int sampleid)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from RatioResults where SampleId='" + sampleid + "'");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratio results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpRatioResults(IList<RatioResults> results)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpRatioResults (Id, Name, Numerator, Denominator, SampleId, Label,\r\n                               Number,Result,CaliResult,STDResult,Beta)\r\n                                         VALUES (@Id, @Name, @Numerator, @Denominator, @SampleId, @Label,\r\n                               @Number,@Result,@CaliResult,@STDResult,@Beta)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (RatioResults result in results)
				{
					count = (result.Id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@Id", (object)result.Id);
					insertRngCmd.Parameters.AddWithValue("@Name", (object)result.Name);
					insertRngCmd.Parameters.AddWithValue("@Numerator", (object)result.Numerator);
					insertRngCmd.Parameters.AddWithValue("@Denominator", (object)result.Denominator);
					insertRngCmd.Parameters.AddWithValue("@SampleId", (object)result.SampleId);
					insertRngCmd.Parameters.AddWithValue("@Label", (object)result.Label);
					insertRngCmd.Parameters.AddWithValue("@Number", (object)result.Number);
					insertRngCmd.Parameters.AddWithValue("@Result", (object)result.Result);
					insertRngCmd.Parameters.AddWithValue("@CaliResult", (object)result.CaliResult);
					insertRngCmd.Parameters.AddWithValue("@STDResult", (object)result.STDResult);
					insertRngCmd.Parameters.AddWithValue("@Beta", (object)result.Beta);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpRatioResults Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public IList<RatioStatistics> GetExpRatioStatistics()
	{
		IList<RatioStatistics> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(RatioStatistics)).List<RatioStatistics>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			results = null;
			InserLog("Database", "Get isotope ratio statistics error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpRatioStatistics()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from RatioStatistics");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratios statstics error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteExpRatioStatistics(int sampleid)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from RatioStatistics where SampleId='" + sampleid + "'");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratios statstics error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpRatioStatstics(IList<RatioStatistics> results)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpRatioStatistics (Id, Name, Numerator, Denominator, SampleId, Label,\r\n                               Avg,Sd,Rsd,STD,Beta,CaliAvg)\r\n                                         VALUES (@Id, @Name, @Numerator, @Denominator, @SampleId, @Label,\r\n                                @Avg,@Sd,@Rsd,@STD,@Beta,@CaliAvg)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (RatioStatistics result in results)
				{
					count = (result.Id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@Id", (object)result.Id);
					insertRngCmd.Parameters.AddWithValue("@Name", (object)result.Name);
					insertRngCmd.Parameters.AddWithValue("@Numerator", (object)result.Numerator);
					insertRngCmd.Parameters.AddWithValue("@Denominator", (object)result.Denominator);
					insertRngCmd.Parameters.AddWithValue("@SampleId", (object)result.SampleId);
					insertRngCmd.Parameters.AddWithValue("@Label", (object)result.Label);
					insertRngCmd.Parameters.AddWithValue("@Avg", (object)result.Avg);
					insertRngCmd.Parameters.AddWithValue("@Sd", (object)result.Sd);
					insertRngCmd.Parameters.AddWithValue("@Rsd", (object)result.Rsd);
					insertRngCmd.Parameters.AddWithValue("@STD", (object)result.STD);
					insertRngCmd.Parameters.AddWithValue("@Beta", (object)result.Beta);
					insertRngCmd.Parameters.AddWithValue("@CaliAvg", (object)result.CaliAvg);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpRatioResults Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public IList<SpectrumInfos> GetExpSpectrums()
	{
		IList<SpectrumInfos> spectrums = null;
		ISession session = GetSession();
		try
		{
			spectrums = session.CreateCriteria(typeof(SpectrumInfos)).List<SpectrumInfos>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			spectrums = null;
			InserLog("Database", "Get spectrums error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return spectrums;
	}

	public bool DeleteExpSpectrums()
	{
		DateTime time1 = DateTime.Now;
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "delete from ExpSpectrumInfos";
				SQLiteTransaction transaction = dest.BeginTransaction();
				((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				((DbTransaction)(object)transaction).Commit();
				TimeSpan timeSpan = DateTime.Now - time1;
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "DeleteExpSpectrums Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public bool DeleteExpSpectrums(int sampleid)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from SpectrumInfos where sampleid ='" + sampleid + "'");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete spectums error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpSpectrums(IList<SpectrumInfos> spectrums)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (SpectrumInfos std in spectrums)
				{
					std.id = 0;
					session.Save((object)std);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save std concentrations error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<IsotopeCurve> GetExpCurves()
	{
		IList<IsotopeCurve> curves = null;
		ISession session = GetSession();
		try
		{
			curves = session.CreateCriteria(typeof(IsotopeCurve)).List<IsotopeCurve>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			curves = null;
			InserLog("Database", "Get curves error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return curves;
	}

	public bool DeleteExpCurves()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IsotopeCurve");
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete curves error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpCurves(IList<IsotopeCurve> curves)
	{
		try
		{
			SQLiteCommand insertRngCmd = dest.CreateCommand();
			try
			{
				((DbCommand)(object)insertRngCmd).CommandText = "INSERT INTO ExpIsotopeCurve (id, isotopeId, symbol, intercept1, intercept2, k,\r\n                               b,r,calculated,method,points,groupId)\r\n                                         VALUES  (@id, @isotopeId, @symbol, @intercept1, @intercept2, @k,\r\n                               @b,@r,@calculated,@method,@points,@groupId)";
				SQLiteTransaction transaction = dest.BeginTransaction();
				int count = 0;
				foreach (IsotopeCurve result in curves)
				{
					count = (result.id = count + 1);
					insertRngCmd.Parameters.AddWithValue("@id", (object)result.id);
					insertRngCmd.Parameters.AddWithValue("@isotopeId", (object)result.isotopeId);
					insertRngCmd.Parameters.AddWithValue("@symbol", (object)result.symbol);
					insertRngCmd.Parameters.AddWithValue("@intercept1", (object)result.intercept1);
					insertRngCmd.Parameters.AddWithValue("@intercept2", (object)result.intercept2);
					insertRngCmd.Parameters.AddWithValue("@k", (object)result.k);
					insertRngCmd.Parameters.AddWithValue("@b", (object)result.b);
					insertRngCmd.Parameters.AddWithValue("@r", (object)result.r);
					insertRngCmd.Parameters.AddWithValue("@calculated", (object)result.calculated);
					insertRngCmd.Parameters.AddWithValue("@method", (object)result.method);
					insertRngCmd.Parameters.AddWithValue("@points", (object)result.points);
					insertRngCmd.Parameters.AddWithValue("@groupId", (object)result.groupId);
					((DbCommand)(object)insertRngCmd).ExecuteNonQuery();
				}
				((DbTransaction)(object)transaction).Commit();
				return true;
			}
			finally
			{
				((IDisposable)insertRngCmd)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("保存数据库", "SaveExpCurves Fail", ex.Message, (Severity)3);
			return false;
		}
	}

	public ScanParams GetExpParams()
	{
		ScanParams scanParams = null;
		ISession session = GetSession();
		try
		{
			IList<ScanParams> tmpParams = session.CreateCriteria(typeof(ScanParams)).List<ScanParams>();
			if (tmpParams != null && tmpParams.Count != 0)
			{
				scanParams = tmpParams.First();
			}
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			scanParams = null;
			InserLog("Database", "Get scan params error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return scanParams;
	}

	public bool SaveExpParams(ScanParams param)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)param);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save scan params error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public QCSPara GetQCSPara()
	{
		QCSPara qcsPara = null;
		ISession session = GetSession();
		try
		{
			IList<QCSPara> tmpParams = session.CreateCriteria(typeof(QCSPara)).List<QCSPara>();
			if (tmpParams != null && tmpParams.Count != 0)
			{
				qcsPara = tmpParams.First();
			}
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			qcsPara = null;
			InserLog("Database", "Get qcs params error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return qcsPara;
	}

	public bool SaveQCSPara(QCSPara para)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)para);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save qcs params error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public ReportParams GetReportParams()
	{
		ISession session = GetSession();
		try
		{
			IList<ReportParams> ps = session.CreateCriteria(typeof(ReportParams)).List<ReportParams>();
			if (ps != null)
			{
				return ps.Last();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("方法数据库", "获取报表参数", ex.Message, (Severity)3);
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public bool SaveReportParams(ReportParams p)
	{
		ISession session = GetSession();
		try
		{
			ITransaction t = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)p);
				session.Flush();
				t.Commit();
				return true;
			}
			catch (Exception ex)
			{
				t.Rollback();
				Log.InsertLog("方法数据库", "保存报表参数", ex.Message, (Severity)3);
				LastException = ex;
			}
			finally
			{
				((IDisposable)t)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	private void WriteConsole(string msg)
	{
	}

	public bool WriteToLocal()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		try
		{
			SQLiteConnection conn = new SQLiteConnection("Data Source=" + localDb + ";Version=3");
			try
			{
				((DbConnection)(object)conn).Open();
				dest.BackupDatabase(conn, "main", "main", -1, (SQLiteBackupCallback)null, 100);
				((DbConnection)(object)conn).Close();
				return true;
			}
			finally
			{
				((IDisposable)conn)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("数据库", "保存方法至本地", ex.Message, (Severity)3);
			return false;
		}
	}

	public void ReConnect(string dbPath)
	{
		localDb = dbPath;
	}

	private void InserLog(string category, string content, string detail, string severity)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Log.InsertLog(category, content, detail, (Severity)Enum.Parse(typeof(Severity), severity));
	}
}
